/*
 * 企业管理
 */

import { createAPI } from '@/utils/request'
import * as URL from '../../constants/api'
// export const list = data => createAPI('/companys', 'get', data)
// export const add = data => createAPI('/companys', 'post', data)
// export const update = data => createAPI(`/companys/${data.id}`, 'put', data)
// export const remove = data => createAPI(`/companys/${data.id}`, 'delete', data)
// export const detail = data => createAPI(`/companys/${data.id}`, 'get', data)
// export const disabled = data =>
//   createAPI(`/companys/${data.id}/state`, 'post', data)

// import instance from '@/utils/request'

// export function getcompanysList(params) {
//   return instance({
//     // production 生产环境
//     url: URL.COMPANYS,
//     params,
//   })
//     .then(res => res.data.data)
//     .catch(() => [])
// }
const formOfEmploymentMapping = new Map([
  [1, '启用'],
  [0, '禁用'],
  ['1', '启用'],
  [2, '禁用']
])
// 查看列表
export const getcompanysList = data => createAPI(URL.COMPANYS, 'get', data)
  .then(res => ({
    items: res.data.items.map(p => ({
      ...p,
      state: formOfEmploymentMapping.get(p.state)
    })),
    counts: res.data.counts,
    page: res.data.page,
    pages: res.data.pages,
    pagesize: res.data.pagesize
  }))
  .catch(() => {})

  // 新增用户
  export const add = data => createAPI(URL.COMPANYS, 'post', data)
  .then(res => res.data)
  .catch(() => {})

  // 删除用户
  export const deleteUse = data => createAPI(`${URL.COMPANYS}/${data.id}`, 'delete', data)
  .then(res => res)
  .catch(() => {})
